<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class Upload
{
    public $login = false; //是否需要登录才能访问该接口
    public $title = "上传图片ok";
    public $group = '公用';
    public $desc = "";

    public $input = [
//        'kcs_uploader_file' => 'required;file;label=图片文件;',
    ];

    public $output = [
        'url' => 'label=图片地址;',
    ];

    public function run($param, $uid)
    {
        $result = OE('file')->upload();
        //$re = OE('user')->qrcode($uid);
        $data = json_decode($result, true);
        return [
            'url' => $data['result']['url']
        ];
    }

    private function uploadOne($filename = 'file',$type = 'jpeg|png|bmp|jpg',$maxSize = 10240)
    {
        list($width,$height)    = getimagesize($_FILES[$filename]['tmp_name']); // 获取图片的宽和高
        list($usec, $sec) = explode(" ", microtime());
        $time = $sec.substr($usec,2);                         // 秒数+微秒数
        $ext = substr($_FILES[$filename]['name'],strrpos($_FILES[$filename]['name'],'.')+1); // 上传文件后缀
        $name   = $time.'-'.$width.'*'.$height.'.'.$ext;
        $filePath = $_FILES[$filename]['tmp_name'];
        $type   = $_FILES[$filename]['type'];

//        $returnData['url'] = $this->qiniu->upload($name,$filePath,$type);
        copy($filePath, UPLOAD_PATH . $name);
        $returnData['url'] = '/upload/' . $name;
        $returnData['status'] = 0;
        return $returnData;
    }
}
